#!/usr/bin/python
import json
import cgi
import sys
import base64
import HTMLParser
import string

h = HTMLParser.HTMLParser()
qform = cgi.FieldStorage()
fileName = qform.getvalue('fileName')
sequence = qform.getvalue('data')
contentType = "text/plain"
#logs = open("vials.txt", "a")
try:
	h = HTMLParser.HTMLParser()
	#sequence = string.replace( sequence, '\r', '' )
	sequence = h.unescape(sequence)
	seqlines = sequence.split("\n")
	outseq = ""
	for s in seqlines:
		outseq = outseq + s.strip() + "\n"
	
	"""if (pomoType == "csv"):
		for e in pedges:		
			estr = estr + e[0] + "," + e[1]
			if (len(e) > 2):
				estr = estr + "," + e[2].strip()
			estr = estr + "\r\n"
	"""
	#logs.write(sequence + "\n")
	#logs.close()
	print "Content-Type: " + contentType #text/plain"
	#print "Content-Type: application/octet-stream"
	print "Content-Disposition: attachment; filename=" + fileName
	print
	print outseq
except IOError as e:
    print "Error %s:" % str(e)



